import { DataTypes, Model } from 'sequelize'
import { sequelize } from '../../connect'
import { findAllValues, findOneRandomValue, findOneValue } from '../../public'

type ModelProps = {
  id: number // 表id
  name: number // 地图
  thing: string // 名称
  type: string // 类型
  begin: number // 初始数量
  speed: number // 生成速率
  min: number // 数量下限
  max: number // 数量上限
  detail?: JSON // 详情
}

class map_setting extends Model<ModelProps> {
  public static findAllValues = findAllValues
  public static findOneValue = findOneValue
  public static findOneRandomValue = findOneRandomValue
}

map_setting.init(
  {
    id: {
      type: DataTypes.BIGINT,
      primaryKey: true,
      allowNull: false,
      autoIncrement: true,
      comment: '表id'
    },
    name: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '地图'
    },
    thing: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '名称'
    },
    type: {
      type: DataTypes.STRING(50),
      allowNull: false,
      comment: '类型'
    },
    begin: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '初始数量'
    },
    speed: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '生成速率'
    },
    min: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '数量下限'
    },
    max: {
      type: DataTypes.INTEGER,
      allowNull: true,
      defaultValue: 0,
      comment: '数量上限'
    },
    detail: {
      type: DataTypes.JSON,
      allowNull: true,
      comment: '详情'
    }
  },
  {
    sequelize,
    tableName: 'map_setting',
    freezeTableName: true,
    createdAt: false,
    updatedAt: false,
    indexes: [
      {
        unique: false,
        fields: ['id']
      }
    ]
  }
)

export { map_setting }
